//
//  HZC_BaceView.m
//  Co8
//
//  Created by Hanzengchao on 2017/11/1.
//

#import "YYJ_BaseView.h"

@implementation YYJ_BaseView

-(instancetype)init{
    self = [super init];
    if(self){
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    if (self.corners) {
        UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:self.corners cornerRadii:CGSizeMake(self.cornerRadius, self.cornerRadius)];
        CAShapeLayer* shape = [[CAShapeLayer alloc] init];
        [shape setPath:rounded.CGPath];
        
        self.layer.mask = shape;
    }else if(self.isRound){
        CGFloat xxx = CGRectGetWidth(self.frame);
        if (xxx>CGRectGetHeight(self.frame)) {
            xxx = CGRectGetHeight(self.frame);
        }
        self.layer.cornerRadius = xxx/2.0f;
    }
    else{
        self.layer.cornerRadius = self.cornerRadius;
    }
}
+(void)kChangeBoard:(BOOL)kWarning withView:(UIView *)kView andColor:(UIColor *)color{
    kView.layer.borderColor = color.CGColor;
    kView.layer.borderWidth = 0.6f;
}
-(void)setCorners:(UIRectCorner)corners{
    _corners = corners;
    [self layoutSubviews];
}
-(void)setIsRound:(BOOL)isRound{
    _isRound = isRound;
    [self layoutSubviews];
}
-(void)setCornerRadius:(CGFloat)cornerRadius{
    _cornerRadius = cornerRadius;
    [self layoutSubviews];
}
-(void)setBorderWidth:(CGFloat)borderWidth{
    _borderWidth = borderWidth;
    self.layer.borderWidth = borderWidth;
}
-(void)setBorderColor:(UIColor *)borderColor{
    _borderColor = borderColor;
    self.layer.borderColor = borderColor.CGColor;
}
-(void)kChangeBoard:(BOOL)kWarning withView:(UIView*) kView{
    if(kWarning){
        kView.layer.borderColor = [UIColor redColor].CGColor;
        kView.layer.borderWidth = 0.6f;
        kView.layer.cornerRadius = 6.0f;
    }else{
        kView.layer.borderColor =[UIColor clearColor].CGColor;
        kView.layer.borderWidth = 0;
        kView.layer.cornerRadius = 0.0f;
    }
}
-(void)kChangeTextfilePlaceholderColor:(UITextField*) kTextFile withWarning:(BOOL) kWarning{
    kWarning?[kTextFile setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]:[kTextFile setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
}
-(void)kChangeLabel:(UILabel*) kLabel withWaring:(BOOL) kWarning{
//    kLabel.textColor = kWarning?[UIColor redColor]:[UIColor colorWithHexString:@"9B9B9B"];
}
-(void)setSelfFrame:(CGFloat)spacing{
    self.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetMaxY(self.subviews.lastObject.frame)+spacing);
    if (self.kReloadViewBlock) {
        self.kReloadViewBlock();
    }
}

//-(void)setShadowColor:(UIColor *)shadowColor{
//    _shadowColor = shadowColor;
//    self.layer.shadowColor = shadowColor.CGColor;
//}
//-(void)setShadowRadius:(CGFloat)shadowRadius{
//    _shadowRadius = shadowRadius;
//    self.layer.shadowRadius = shadowRadius;
//}
//-(void)setShadowOffset:(CGSize)shadowOffset{
//    _shadowOffset = shadowOffset;
//    self.layer.shadowOffset = shadowOffset;
//}
//-(void)setShadowOpacity:(CGFloat)shadowOpacity{
//    _shadowOpacity = shadowOpacity;
//    self.layer.shadowOpacity = shadowOpacity;
//}

-(void)viewWillDisAp{
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
